home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / telecom / 133 / c / getenv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-04-17  |  3.0 KB  |  58 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /* Module:     getopt.c - Scan environment area for matching string         */
  4. /*                                                                          */
  5. /* Programmer: David Beckemeyer, with modifications by George R. Woodside   */
  6. /*                                                                          */
  7. /* Date:       January 7, 1987                                              */
  8. /*                                                                          */
  9. /* Function:   Search the environment area for a named environment string.  */
  10. /*             Return a null if string is not found.                        */
  11. /*             Return a pointer to the associated environment variable if   */
  12. /*             the input string is found.                                   */
  13. /*                                                                          */
  14. /****************************************************************************/
  15.  
  16. #include <basepage.h>
  17.  
  18. char *getenv(ustring)                   /* note that return is a char *     */
  19. char *ustring;
  20. {
  21.   char *temp;
  22.   char *user;
  23.   struct b_page *bpage;                 /* Basepage pointer                 */
  24.  
  25.   bpage = _base;                        /* assign the basepage pointer      */
  26.   temp=(char *)(bpage->p_env);          /* pointer to environment strings   */
  27.  
  28.   while ((*temp)!=0)                    /* while there are strings to check */
  29.     {
  30.       user=ustring;                     /* load start of user's string      */
  31.       while((*temp)==(*user))           /* while the characters match,      */
  32.         {
  33.           temp++;                       /* move environment up              */
  34.           user++;                       /* and user string up               */
  35.         }                               /* end bytes match                  */
  36.  
  37.       /**********************************************************************/
  38.       /* If the environment string is now at "=", and the user string is    */
  39.       /* at it's end, then we have a match.                                 */
  40.       /**********************************************************************/
  41.  
  42.       if ((*temp) == '=' && (*user) == 0) /* if it matched,                 */
  43.         {
  44.           if (*(++temp)==0)             /* and next byte is null,           */
  45.             temp++;                     /* point to next value              */
  46.           return temp;                  /* and return that                  */
  47.         }
  48.  
  49.       if ((*temp)!=0)                   /* if environment string not ended  */
  50.         {
  51.           while ((*(temp++))!=0);       /* skip to the end                  */
  52.         }
  53.       else                              /* otherwise,                       */
  54.         temp++;                         /* move to next string              */
  55.     }
  56.     return(0);                          /* if we get here, no matches       */
  57. }
  58.